"""通用工具类"""
"""
测试数据是否为空
"""
def isEmpty(data):
    if data is None:
        return True
    if isinstance(data, str):
        return len(data.strip()) == 0
    if isinstance(data, int) or isinstance(data, float) or isinstance(data, complex) or isinstance(data, bool):
        return False
    return len(data) == 0

"""
分组
    * data：分组数据
    * key：分组项函数
    * value：分组值函数，默认本身
"""
def group(data,key,value=lambda i:i):
    group_dict = {}
    for i in data:
        _key = key(i)
        if _key not in group_dict:
            group_dict[_key] = []
        group_dict[_key].append(value(i))
    return group_dict

"""
list去重
"""
def unique(data):
    unique_list = []
    for i in data:
        if i not in unique_list:
            unique_list.append(i)
    return unique_list
"""
测试用例
"""
# print(group([
#     [1,2,3],
#     [1,2,5],
#     [1,5,6]
# ],key = lambda i:i[1],value= lambda i:sum(i)))
#
# print(group([
#     {"name":"张三","class":"1"},
#     {"name":"李四","class":"2"},
#     {"name":"王五","class":"1"},
# ],key = lambda i:i["class"]))

